package com.neusoft.utils.tpl.directive;

import java.util.List;

import com.neusoft.utils.json.JsonUtil;

import freemarker.template.SimpleSequence;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

public class JsonMethod implements TemplateMethodModelEx {

	@Override
	public Object exec(List args) throws TemplateModelException {
		Object bean=args.get(0);
		
		String result=null;
		if(bean instanceof SimpleSequence){
			SimpleSequence beanx=(SimpleSequence) bean;
			 result=JsonUtil.toJson(beanx.toList());
			return result;
		}
		result=JsonUtil.toJson(bean);
		// TODO Auto-generated method stub
		return result;
	}
}